package com.rd.teacher.jichao.day11;

public class TestRunnable1 implements Runnable {

    int i;

    @Override
    public void run() {
        for (; i < 50; i++) {
            System.out.println(Thread.currentThread().getName()
                    + " " + i);
        }
    }


    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
//            System.out.println(Thread.currentThread().getName()
//                    + " " + i);

            // 如果此时需要i变量是连续的  使用同一个runnable对象
            // 如果仍然需要i变量是独立的  使用不同的runnable对象
            if (i == 10) {
                TestRunnable1 tr = new TestRunnable1();
                Thread thread1 = new Thread(tr);
                thread1.start();

                TestRunnable1 tr2 = new TestRunnable1();
                Thread thread2 = new Thread(tr2);
                thread2.start();
            }

            // 此时i是连续的吗
            // thread1和thread2是同时操作它吗
        }
    }
}
